<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container ">
        <form name="infoForm">
            <fieldset>
                <legend>客户意见表</legend>
                <div class="form-group">
                    <label for="exampleInputEmail1">兑换卡类型</label>
                    <input type="text"
                    class="form-control"
                    name="539"
                    placeholder="请输入兑换卡类型">
                </div>
                <div class="form-group">
                    <label for="exampleInputEmail1">推荐人</label>
                    <input type="text"
                    class="form-control"
                    name="540"
                    placeholder="推荐人">
                </div>
                <div class="form-group">
                    <label for="exampleInputEmail1">地址</label>
                    <input type="text"
                    class="form-control"
                    name="546"
                    placeholder="地址">
                </div>
                <button class="btn btn-default" type="submit">Submit</button>
            </fieldset>
        </form>
    </div>
    <script>
        // ajax 数据提交一下？
        let signInfo = [
          {
            fiedId: 539,
            value: undefined
          },
          {
            fiedId: 540,
            value: undefined
          },
          {
            fiedId: 546,
            value: undefined
          },
        ];
        const oForm = document.forms["infoForm"];
        oForm.addEventListener("submit",function(event) {
            event.preventDefault();
            const formData = new FormData(this);
            // console.log(formData);
            if(formData.get('539')) {
                // console.log(formData.get('539'));
                signInfo[0].value = formData.get('539')
            }

            if(formData.get('540')) {
                // console.log(formData.get('539'));
                signInfo[1].value = formData.get('540')
            }

            if(formData.get('546')) {
                // console.log(formData.get('539'));
                signInfo[2].value = formData.get('546')
            }
            // console.log(signInfo,"---------");
            let str = JSON.stringify(signInfo);
            // console.log(str);
            fetch('/info?data=' + str)
            .then(data => data.json())
            .then(data => {
                console.log(data);
            })
        })
    </script>
</body>
</html>